package com.efrei.uchat.server;

import com.efrei.uchat.message.Headers;
import com.efrei.uchat.server.strategies.CroomListWorker;
import com.efrei.uchat.server.strategies.CroomUsersWorker;
import com.efrei.uchat.server.strategies.CroomWorker;
import com.efrei.uchat.server.strategies.MessageStrategy;
import com.efrei.uchat.server.strategies.TextWorker;

public enum MessageStrategies {
	TEXT_ASSOCIATION(Headers.TEXT, TextWorker.class),
	TEXT_C_ASSOCIATION(Headers.TEXT_CHANNEL, TextWorker.class),
	CROOM_ASSOCIATION(Headers.CROOM_MESSAGE, CroomWorker.class),
	CROOM_LIST_ASSOCIATION(Headers.CROOM_LIST_MESSAGE, CroomListWorker.class),
	CROOM_USERS_ASSOCIATION(Headers.CROOM_USERS_MESSAGE, CroomUsersWorker.class);
	
	private Headers type;
	private Class<MessageStrategy> strategy;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private MessageStrategies(Headers type, Class strategy) {
		this.type = type;
		this.strategy = strategy;
	}
	
	public static Class<MessageStrategy> getMessageStrategy(Headers type) {
		for (MessageStrategies messageStrategy : values()) {
			if(type.equals(messageStrategy.type)) {
				return messageStrategy.strategy;
			}
		}
		return null;
	}
}
